﻿using System.Collections.Generic;
using Engine;
using Game;
using GameEntitySystem;
using TemplatesDatabase;

public class 使用 : SubsystemBlockBehavior, IUpdateable
{
    public SubsystemTerrain m_subsystemTerrain;

    public SubsystemTime m_subsystemTime;

    public SubsystemProjectiles m_subsystemProjectiles;

    public SubsystemParticles m_subsystemParticles;

    public SubsystemAudio m_subsystemAudio;

    public SubsystemNoise m_subsystemNoise;

    public SubsystemPlayers m_subsystemPlayers;

    public SubsystemGameInfo m_subsystemGameInfo;

    public ComponentLevel m_componentLevel;

    public Game.Random m_random = new Game.Random();

    public Dictionary<ComponentMiner, double> m_aimStartTimes = new Dictionary<ComponentMiner, double>();

    public override int[] HandledBlocks => new int[0];

    public ComponentPlayer componentPlayer;

    public ComponentMiner componentMiner;
    public float GunChangeActionPross = 0f;

    public IInventory m_inventory;

    public int m_slotIndex;

    public UpdateOrder UpdateOrder
    {
        get
        {
            return 0;
        }
    }

    public void Update(float dt)
    {
    }
    public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
    {

        int activeBlockValue = componentMiner.ActiveBlockValue;
        int num66 = Terrain.ExtractContents(activeBlockValue);
        IInventory inventory = componentMiner.Inventory;
        ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent<ComponentFirstPersonModel>();
        componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.4f;
        componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(-0.08f, -0.08f, 0.07f);
        componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
        componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.21f, 0.15f, 0.08f);
        componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);

        //灵丹
        NK9 nk = componentMiner.ComponentPlayer.Entity.FindComponent<NK9>();
        if (num66 == 586)
        {
            if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("正在吸收灵丹", Color.LightRed, blinking: true, playNotificationSound: false);
            }

            if (m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0))
            {
                componentMiner.ComponentPlayer.PlayerData.Level += (0.1f / componentMiner.ComponentPlayer.PlayerData.Level);
                nk.Water += 0.05f;
                componentMiner.RemoveActiveTool(1);
            }

        }

        if (num66 == 591)
        {
            if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("正在吸收灵丹", Color.LightRed, blinking: true, playNotificationSound: false);
            }

            if (m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0))
            {
                componentMiner.ComponentPlayer.PlayerData.Level += (10f / componentMiner.ComponentPlayer.PlayerData.Level);
                nk.Water += 0.5f;
                componentMiner.RemoveActiveTool(1);
                componentMiner.ComponentPlayer.Project.FindSubsystem<SubsystemSky>().MakeLightningStrike(componentMiner.ComponentPlayer.ComponentBody.Position + m_random.Vector3(5f));
            }

        }

        //         灵晶   
        if (num66 == 570)
        {
            if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("正在吸收灵晶", Color.LightRed, blinking: true, playNotificationSound: false);
            }

            if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0))
            {

                componentMiner.ComponentPlayer.PlayerData.Level += (0.1f / componentMiner.ComponentPlayer.PlayerData.Level);
                componentMiner.RemoveActiveTool(1);
            }

        }

        if (num66 == 571 && componentMiner.ComponentPlayer.PlayerData.Level == 9f)
        {

            componentMiner.ComponentPlayer.PlayerData.Level = 10f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁10级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁10级", 5f, 0f);
            componentMiner.RemoveActiveTool(1);
        }



        if (num66 == 571 && componentMiner.ComponentPlayer.PlayerData.Level < 9)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足9", Color.LightRed, blinking: true, playNotificationSound: false);
        }

        if (num66 == 572 && componentMiner.ComponentPlayer.PlayerData.Level < 19)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足19", Color.LightRed, blinking: true, playNotificationSound: false);
        }
        if (num66 == 573 && componentMiner.ComponentPlayer.PlayerData.Level < 29)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足29", Color.LightRed, blinking: true, playNotificationSound: false);
        }
        if (num66 == 574 && componentMiner.ComponentPlayer.PlayerData.Level < 39)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足39", Color.LightRed, blinking: true, playNotificationSound: false);
        }
        if (num66 == 575 && componentMiner.ComponentPlayer.PlayerData.Level < 49)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足49", Color.LightRed, blinking: true, playNotificationSound: false);
        }
        if (num66 == 576 && componentMiner.ComponentPlayer.PlayerData.Level < 59)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("等级不足59", Color.LightRed, blinking: true, playNotificationSound: false);
        }


        if (num66 == 572 && componentMiner.ComponentPlayer.PlayerData.Level == 19f)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁20级", 5f, 0f);
            componentMiner.ComponentPlayer.PlayerData.Level = 20f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁20级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.RemoveActiveTool(1);

        }

        if (num66 == 573 && componentMiner.ComponentPlayer.PlayerData.Level == 29f)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁30级", 5f, 0f);
            componentMiner.ComponentPlayer.PlayerData.Level = 30f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁30级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.RemoveActiveTool(1);

        }

        if (num66 == 574 && componentMiner.ComponentPlayer.PlayerData.Level == 39f)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁40级", 5f, 0f);
            componentMiner.ComponentPlayer.PlayerData.Level = 40f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁40级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.RemoveActiveTool(1);

        }

        if (num66 == 575 && componentMiner.ComponentPlayer.PlayerData.Level == 49f)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁50级", 5f, 0f);
            componentMiner.ComponentPlayer.PlayerData.Level = 50f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁50级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.RemoveActiveTool(1);

        }

        if (num66 == 576 && componentMiner.ComponentPlayer.PlayerData.Level == 59f)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplayLargeMessage("提示", "已解锁60级", 5f, 0f);
            componentMiner.ComponentPlayer.PlayerData.Level = 60f;
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("已解锁60级", Color.LightRed, blinking: true, playNotificationSound: false);
            componentMiner.RemoveActiveTool(1);

        }

        return false;
    }

    public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
    {
        int activeBlockValue = componentMiner.ActiveBlockValue;
        int num66 = Terrain.ExtractContents(activeBlockValue);
        if (num66 != 0)
        {
            componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage("请长按屏幕使用，卷轴放在副物品栏", Color.White, blinking: true, playNotificationSound: false);
        }
        return false;
    }


    public override void Load(ValuesDictionary valuesDictionary)
    {
        m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(throwOnError: true);
        m_subsystemPlayers = Project.FindSubsystem<SubsystemPlayers>(throwOnError: true);
        m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(throwOnError: true);
        m_subsystemTime = Project.FindSubsystem<SubsystemTime>(throwOnError: true);
        m_subsystemProjectiles = Project.FindSubsystem<SubsystemProjectiles>(throwOnError: true);
        m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(throwOnError: true);
        m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(throwOnError: true);
        m_subsystemNoise = Project.FindSubsystem<SubsystemNoise>(throwOnError: true);
        base.Load(valuesDictionary);
    }
}
